package io.github.chutian0610.sqlparser.token

import io.github.chutian0610.sqlparser.Section
import io.github.chutian0610.sqlparser.token.Token.EOF

data class TokenWithLocation(
    val token: Token,
    val section: Section
) {
    override fun equals(other: Any?): Boolean {
        if (this === other) return true
        return when (other) {
            is TokenWithLocation -> {
                other.token == this.token && other.section == this.section
            }

            is Token -> other == token
            else -> false
        }
    }

    override fun hashCode(): Int {
        return token.hashCode()
    }

    override fun toString(): String {
        return token.toString()
    }

    companion object {
        fun at(token: Token, section: Section): TokenWithLocation {
            return TokenWithLocation(token, section)
        }

        fun eof(): TokenWithLocation {
            return TokenWithLocation(EOF, Section.EMPTY)
        }

        fun wrap(token: Token): TokenWithLocation {
            return TokenWithLocation(token, Section.EMPTY)
        }
    }
}